using UnityEngine;
using System.Collections;

public class Skill_effect : MonoBehaviour
{
	public ParticleSystem head;
	public ParticleSystem tail;

	//public GameObject hited = null;
	public Character Hited_sc;
	public Character Hiter_sc;
	public Transform hited_pos;
	public float speed;
	public Damage damage;
	private bool _activation = false;
	public bool activation
	{
		get
		{
			return _activation;
		}
		set
		{
			gameObject.SetActive(true);
			_activation = value;
		}
	}

	// Use this for initialization
	void Start ()
	{
		gameObject.SetActive(false);
	}
	
	// Update is called once per frame
	void Update ()
	{
		if (activation && Hited_sc != null) 
		{
			transform.position = Vector3.Lerp(transform.position, hited_pos.position,speed* Time.deltaTime);
		}
	}

	public void ini(Damage dmg,Character hiter_sc, Character hited_sc,float sp = 2f)
	{
		damage = dmg;
		Hited_sc = hited_sc;
		Hiter_sc = hiter_sc;
		hited_pos = hited_sc.hited_pos;
		speed = sp;
	}

	void OnTriggerEnter(Collider collider)
	{
		if (collider.gameObject == Hited_sc.gameObject) 
		{
			Hited_sc.be_hited(damage);
			Hiter_sc.be_hiter_end(damage);
			Destroy(gameObject);
		}
	}
}
